package library.and.xps.com.step.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.CheckJoinTeamPassRes;

public class DepartmentsInJoinTeamAdapter extends ArrayAdapter {
    private List<CheckJoinTeamPassRes.ListBean> joinRes;
    private LayoutInflater layoutInflater;

    public DepartmentsInJoinTeamAdapter(Context context, List<CheckJoinTeamPassRes.ListBean> joinRes) {
        super(context, R.layout.jointeam_departselect_item);
        layoutInflater = LayoutInflater.from(context);
        this.joinRes = joinRes;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return joinRes.size();
    }

    @Override
    public Object getItem(int position) {
        return joinRes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;
        CheckJoinTeamPassRes.ListBean listBean = joinRes.get(position);
        if (view == null) {
            view = layoutInflater.inflate(R.layout.jointeam_departselect_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) view.findViewById(R.id.text_view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.textView.setText(listBean.getDName());

        return view;
    }

    static class ViewHolder {
        TextView textView;
    }
}
